package com.intech.android.demo.cms.dao.impl;

import com.intech.android.demo.cms.bo.Category;
import com.intech.android.demo.cms.bo.Region;
import com.intech.android.demo.cms.dao.interfaces.RegionDAO;
import org.hibernate.Criteria;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class RegionHibernateDAO extends CommonDAO implements RegionDAO
{
    public Region getById(Integer id)
    {
        return (Region) session.get(Region.class, id);
    }

    public void save(Region region)
    {
        session.saveOrUpdate(region);
    }

    public void delete(Region region)
    {
        session.delete(region);
    }

    public List<Region> getAll()
    {
        Criteria criteria = session.createCriteria(Region.class);
        List list = criteria.list();
        return list;
    }

    public List<Region> getListById(List<Integer> ids)
    {
        List<Region> regions = new ArrayList<Region>();
        for (int i = 0; i < ids.size(); i++)
        {
            regions.add(getById(ids.get(i)));
        }
        return regions;
    }
}
